using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace UFSControl
{
    public class TaskTrayApplicationContext : ApplicationContext
    {
        NotifyIcon notifyIcon = new NotifyIcon();
        MainForm RemoteWindow = new MainForm();

        public TaskTrayApplicationContext()
        {
            ToolStripMenuItem configMenuItem = new ToolStripMenuItem("Fernbedienung", KRemote.Properties.Resources.Shutdown_Box_Red, new EventHandler(ShowRemoteControl));
            configMenuItem.Font = new Font(configMenuItem.Font, configMenuItem.Font.Style | FontStyle.Bold);
            ToolStripMenuItem senderMenuItem = new ToolStripMenuItem("Senderliste", null, new EventHandler(ShowSenderList));
            ToolStripMenuItem timerMenuItem = new ToolStripMenuItem("Aufnahmeliste", null, new EventHandler(ShowTimerList));
            ToolStripMenuItem archivMenuItem = new ToolStripMenuItem("Medienarchiv", null, new EventHandler(ShowArchivList));
            ToolStripMenuItem exitMenuItem = new ToolStripMenuItem("Beenden", KRemote.Properties.Resources.DeleteRed, new EventHandler(Exit));

            notifyIcon.Icon = KRemote.Properties.Resources.sync;
            notifyIcon.DoubleClick += new EventHandler(ShowRemoteControl);
            notifyIcon.ContextMenuStrip = new ContextMenuStrip();
            notifyIcon.ContextMenuStrip.Items.Add(configMenuItem);
            notifyIcon.ContextMenuStrip.Items.Add(senderMenuItem);
            notifyIcon.ContextMenuStrip.Items.Add(timerMenuItem);
            notifyIcon.ContextMenuStrip.Items.Add(archivMenuItem);
            notifyIcon.ContextMenuStrip.Items.Add(exitMenuItem);
            notifyIcon.Visible = true;

            //beim Starten gleich mal das Fenster anzeigen
            RemoteWindow.ShowDialog();
        }

        void ShowRemoteControl(object sender, EventArgs e)
        {
            // If we are already showing the window meerly focus it.
            if (RemoteWindow.Visible)
                RemoteWindow.Focus();
            else
                RemoteWindow.ShowDialog();
        }

        void ShowConfig(object sender, EventArgs e)
        {
            // Only show the message if the settings say we can.
            //if (KRemote.Properties.Settings.Default.ShowMessage)
            //    MessageBox.Show("Hello World");

            // If we are already showing the window meerly focus it.
            //if (configWindow.Visible)
            //    configWindow.Focus();
            //else
            //    configWindow.ShowDialog();
        }

        void ShowSenderList(object sender, EventArgs e)
        {
            ProgrammList lForm = new ProgrammList();
            lForm.Show();
        }

        void ShowTimerList(object sender, EventArgs e)
        {
            TimerList lForm = new TimerList();
            lForm.Show();
        }

        void ShowArchivList(object sender, EventArgs e)
        {
            ArchivList lForm = new ArchivList();
            lForm.Show();
        }

        void Exit(object sender, EventArgs e)
        {
            // We must manually tidy up and remove the icon before we exit.
            // Otherwise it will be left behind until the user mouses over.
            notifyIcon.Visible = false;

            Application.Exit();
        }
    }
}
